import { GetTypeOf } from "../../../Decorator/Decorator";
import { ITypeBind } from "../../Object/NamedObject";
import { Log } from "../Log/Log";

export interface IEvent {

    Type: string;

}

export class IEvent {


}

export class EventStruct {

}

export interface EventClassConstructor<T> {
    new(): T;
}

export abstract class AEvent<A extends EventStruct> implements IEvent, ITypeBind {

    private _Type: EventClassConstructor<A>;
    constructor() {

    }

    SetupType(type: EventClassConstructor<A>) {
        this._Type = type;
    }

    get Type(): string {
        return GetTypeOf(this._Type);
    }

    async Run(a: A): Promise<any> {
        throw new Error(`子类需要实现该方法!!!`);
    }

    async Handle(a: A): Promise<any> {
        try {
            await this.Run(a);
        } catch (e) {
            Log.Error(e);
        }
    }

}